package com.ttl.bc.ic.stklocation.db;

import hibernate.util.HibernateUtil;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ttl.common.db.ADAO;

public class StkLocationDAO extends ADAO {

	@SuppressWarnings("unchecked")
	public List find(String hql, int maxResults) {
		List result = null;
		Session session = null;

		try {
			SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
			session = sessionFactory.openSession();		
			session.beginTransaction();
			
			Query q = session.createQuery(hql);
			if (maxResults>0) {
				q.setMaxResults(maxResults);
			}
			result = q.list();
			
			session.getTransaction().commit();						
		}catch(Exception e) {			
			System.out.println(e.toString());
		}finally {
			session.close();
		}
		return result;
	}
}
